package cn.gson.springmvc.controller;

import cn.gson.springmvc.model.pojos.Medical;
import cn.gson.springmvc.model.service.YpcMedicalService;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
@Controller
public class YpcMedicalController {

    @Autowired
    YpcMedicalService ypcMedicalService;

    /**
     * 查询所有医疗卡
     * @param currPage
     * @param pageSize
     * @return
     */
    @RequestMapping("/medical-list")
    @ResponseBody
    public Map<String,Object> medical(Integer currPage, Integer pageSize){
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        JSONArray objects = ypcMedicalService.selectMedical();

        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",objects);
        return map;

    }

    @RequestMapping("add-medical")
    @ResponseBody
    public String addMedical(Medical medical,String patientName12){
        try {
            ypcMedicalService.addMedical(medical,patientName12);
            System.out.println(medical.getMedicalName());
            return "success";
        }catch(Exception e){
            return "fails";
        }
    }

    @RequestMapping("change-status")
    @ResponseBody
    public void updateStatus(int medicalId){
        System.out.println("前台数据"+medicalId);
        ypcMedicalService.updateStatus(medicalId);

    }
    @RequestMapping("top-ups")
    @ResponseBody
    public void topUps(int medicalId, String medicalMoney){
        System.out.println("前台数据"+medicalId);
        System.out.println("前台数据"+medicalMoney);
        ypcMedicalService.topUps(medicalId,medicalMoney);
    }

    @RequestMapping("chong-zhi")
    @ResponseBody
    public void chongzhi(int medicalId){
        System.out.println("前台数据"+medicalId);
        ypcMedicalService.chongzhi(medicalId);
    }
    @RequestMapping("select-one")
    @ResponseBody
    public Map<String,Object> selectOne(String patientName12){
        System.out.println("前台数据"+patientName12);
        JSONArray objects = ypcMedicalService.selectOne(patientName12);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",objects);
        return map;

    }
}
